<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #wrapper {
            border: 1px solid #ccc;
            width: 1650px;
            height: 280px;
            margin: 0 auto;
        }
        .imgsDiv{
            width: 100%;
            height: 100%;     
        }
        .imgsDiv li{
            width: 100%;
            height: 100%;
            display: none;
        }

        #dots {
            position: relative;
            top: -70px;
            left: 700px;
            display: flex;
        }

        #dots li {
            list-style: none;
            height: 10px;
            width: 10px;
            border-radius: 50%;
            background-color: red;
            margin: 10px;
        }
    </style>
</head>

<body>
    <div id="wrapper">
        <ul class="imgsDiv">
            <li><img src="./img/logo1.png" /></li>
            <li><img src="./img/logo2.png" /></li>
            <li><img src="./img/logo3.png" /></li>
            <li><img src="./img/logo4.png" /></li>
            
        </ul>
        <ul id="dots">
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <script>

        let imgsDiv = document.getElementsByClassName("imgsDiv")[0];
        let imgs = imgsDiv.getElementsByTagName("li");
        let dots = document.getElementById("dots").getElementsByTagName("li");
        let currentno = 0;

        dots[currentno].style.backgroundColor = "blue";
        imgs[currentno].style.display = "block";
        currentno++;
        //TODO   动态生成li，增加按钮
        function change() {
            for (let index = 0; index < imgs.length; index++) {
                imgs[index].style.display = "none";
                dots[index].style.backgroundColor = "red";
            }
            
            if (currentno === imgs.length) {
                currentno = 0;
            }
  
            imgs[currentno].style.display = "block";
            dots[currentno].style.backgroundColor = "blue";
            currentno++;

        }
        let timer = setInterval("change()", 2000);
        //鼠标 移入暂停轮播
        imgsDiv.onmouseover = () => {
            clearInterval(timer);
        }
        //鼠标 移出继续
        imgsDiv.onmouseout = () => {
            timer = setInterval("change()", 2000);
        }

    </script>
</body>

</html>